package com.web.base.wechat.dao;

import com.blue.jdbc.BaseDao;
import com.web.base.wechat.model.Wechat;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.Map;

@Repository("wechatDao")
public class WechatDao extends BaseDao<Wechat>
{
	public WechatDao()
	{
	}

	@Override
	protected void query(StringBuilder sql, Wechat param)
	{
		if (param != null)
		{
			if (param.getState() != null)
				sql.append(" and a.state=:state");

			if (param.getType() != null)
				sql.append(" and a.type=:type");

			if (param.getCode() != null && !param.getCode().isEmpty())
				sql.append(" and a.code=:code");
			
			if (param.getName() != null && !param.getName().isEmpty())
			{
				sql.append(" and a.name like :name");
				param.setName("%" + param.getName() + "%");
			}
			
		}
		sql.append(" order by a.id");
	}

	public Wechat getByCode(String code)
	{
		Map<String, Object> param = new HashMap<>();
		param.put("code", code);
		String sql = "select * from wx_wechat where code=:code";
		return jdbcObjectTemplate.get(Wechat.class, sql, param);
	}
	
}
